package com.thoughtworks.preuniversityprogram.biblioteca;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by padmavb on 6/10/14.
 */
public  class Library {


    private List<Book> listOfBookObjects=new ArrayList<Book>();
    private List<Book> checkOutBookObjects=new ArrayList<Book>();

    public static void main(String [] args){

        Library library=new Library();
        String unUsedString=library.displayWelcomeMessage();

        while (true){


            int unUsedNumber=library.mainMenu();
        }
    }

    public String displayWelcomeMessage() {

        System.out.print("Welcome\n");
        return "Welcome";
    }

    public void createListOfBookObjects(){

        Book book1=new Book("C","Padma",2013);
        listOfBookObjects.add(book1);

        Book book2=new Book("Maths","John",2014);
        listOfBookObjects.add(book2);

        Book book3=new Book("Data structures","Jack",2012);
        listOfBookObjects.add(book3);

    }




    public int mainMenu() {

        System.out.print("Enter\n1 for List Books\n2 for Quit\n3 for Check out\n4 for Return\n");
        int option=0;

        Scanner scanner=new Scanner(System.in);
        option=Integer.parseInt(scanner.next());

        if(option==1){

            ListBooks listBooks=new ListBooks();
            listOfBookObjects=listBooks.listBooks(checkOutBookObjects);
            return 1;

        }

        else if(option==2)
            System.exit(0);
        else if(option==3){

            //checkOutBookObjects=new CheckOut().checkOutBook("C",checkOutBookObjects);  This is for TDD
            CheckOut checkOut=new CheckOut();
            checkOutBookObjects=checkOut.checkOutBook(readBookTitle(),checkOutBookObjects);
            return 3;
        }
        else if(option==4){

           // checkOutBookObjects=new Return().returnBook("C",checkOutBookObjects);  This is for TDD
            checkOutBookObjects=new Return().returnBook(readBookTitle(),checkOutBookObjects);
            return 4;
        }
        else{

            System.out.print("Select a valid option\n");
        }
        return 0;
    }



    public Book isAvailable(String bookName){

        for(int index=0;index<listOfBookObjects.size();index++){

            if(bookName.equals(listOfBookObjects.get(index).getTitle()))
                return listOfBookObjects.get(index);
        }
        return null;
    }

    public List<Book> getCheckOutBookList() {
        return checkOutBookObjects;
    }



    public List<Book> getListOfBookObjects() {

        return listOfBookObjects;
    }


    public String readBookTitle(){

        Scanner scanner=new Scanner(System.in);
        String bookName=scanner.next();

        return bookName;
    }
}